<?php
namespace Category\Model;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class Category implements InputFilterAwareInterface
{
    public $id;
    public $name;
    public $alias;
    public $disabled;
    protected $inputFilter;
    
    public function exchangeArray($data)
    {
	$this->id = (isset($data['id'])) ? $data['id'] : null;
	$this->name = (isset($data['name'])) ? $data['name'] : null;
	$this->alias = (isset($data['alias'])) ? $data['alias'] : null;
	$this->disabled = (isset($data['disabled'])) ? $data['disabled'] : null;
    }
    
    public function getArrayCopy()
    {
	return get_object_vars($this);
    }
    public function setInputFilter(InputFilterInterface $inputFilter)
    {
	throw new \Exception('Not used');
    }
    public function getInputFilter()
    {
	if (!$this->inputFilter) {
	    $inputFilter = new InputFilter();
	    $factory = new InputFactory();
	    
	    $inputFilter->add($factory->createInput(array(
		'name' => 'id',
		'required' => true,
		'filters' => array(
		    array('name' => 'Int'),
		),
	    )));
	    $inputFilter->add($factory->createInput(array(
		'name' => 'name',
		'required' => true,
		'filters' => array(
		    array('name' => 'StripTags'),
		    array('name' => 'StringTrim'),
		),
		'validators' => array(
		    array(
			'name' => 'StringLength',
			'options' => array(
			    'encoding' => 'UTF-8',
			    'min' => 0,
			    'max' => 40,
			    'messages' => array(
				'stringLengthTooShort' => 'Tên quá ngắn',
				'stringLengthTooLong' => 'Tên quá dài',
			    ),
			),
		    ),
		    array(
			'name' => 'NotEmpty',
			'options' => array(
			    'messages' => array(
				'isEmpty' => 'Hãy nhập vào tên danh mục',
			    ),
			),
		    ),
		),
	    )));
	    $inputFilter->add($factory->createInput(array(
		'name' => 'alias',
		'require' => true,
		'filters' => array(
		    array('name' => 'StripTags'),
		    array('name' => 'StringTrim'),
		),
		'validators' => array(
		    array(
			'name' => 'StringLength',
			'options' => array(
			    'endcoding' => 'UTF-8',
			    'min' => 1,
			    'max' => 40,
			),
		    ),
		),
	    )));
	    $inputFilter->add($factory->createInput(array(
		'name' => 'disabled',
		'required' => false,
		'filters' => array(
		    array('name' => 'Int'),
		),
	    )));
	    $this->inputFilter = $inputFilter;
	}
	return $this->inputFilter;
    }
}